﻿<?php
	require_once('../class/DonDatHangDAO.php');
	require_once('../class/ChiTietDonDatHangDAO.php');
	require_once('../class/NguoiDungDAO.php');
	if(isset($_REQUEST['txtMaDDH']) && isset($_REQUEST['txtSTT']) && isset($_REQUEST['t']))
	{
		$maDDH = $_REQUEST['txtMaDDH'];
		$donDatHang = DonDatHangDAO::LayDDHTheoMaDDH($maDDH);	
		
		if(!is_null($donDatHang))
		{
			$stt = $_REQUEST['txtSTT'];
			$nguoiMuaDto = NguoiDungDAO::LayThongTinNguoiDungTheoMa($donDatHang->MaNguoiDung);
			$tongtien = ChiTietDonDatHangDAO::TinhTongSotienTheoMaDDH($maDDH);
			if (is_null($tongtien))
				$tongtien = 0;
			$ngaydat = date_create($donDatHang->NgayDat);
			$ngaydat = $ngaydat->format('h:m:s d-m-Y');	
			$trangthai = $donDatHang->TrangThai;
			$ngayhuy = "";
			if($trangthai == 1)
			{
				
				$option = 	"<option value='1' selected='selected'>Chờ xử lý</option>
							<option value='2'>Đã liên hệ</option>
							<option value='3'>Hoàn tất</option>
							<option value='4'>Huỷ</option>";
			}
			else if($trangthai == 2)
			{
				$option = 	"<option value='1'>Chờ xử lý</option>
							<option value='2' selected='selected'>Đã liên hệ</option>
							<option value='3'>Hoàn tất</option>
							<option value='4'>Huỷ</option>";
			}
			else if($trangthai == 3)
			{
				$option = 	"<option value='1'>Chờ xử lý</option>
							<option value='2'>Đã liên hệ</option>
							<option value='3' selected='selected'>Hoàn tất</option>
							<option value='4'>Huỷ</option>";
			}
			else if($trangthai == 4)
			{				
				$ngayhuy = date_create($donDatHang->NgayHuy);
				$ngayhuy = $ngayhuy->format('h:m:s d-m-Y');	
				$option = 	"<option value='1'>Chờ xử lý</option>
							<option value='2'>Đã liên hệ</option>
							<option value='3'>Hoàn tất</option>
							<option value='4' selected='selected'>Huỷ</option>";
			}
			$ok_cancel_button = "	<input type='button' value='OK' name='btnOK' onclick='funcLuuCapNhatDDH($stt);'/>
									<input type='button' value='Cancel' name='btnCanCel' onclick='funcHuyCapNhatDDH($stt);'/>							
							  ";
			
			$respone ="
				<td>".$_REQUEST['txtSTT']."</td>
				<td>$maDDH</td>
				<td>$nguoiMuaDto->UserName</td>
				<td>$ngaydat</td>
				<td>$ngayhuy</td>
				<td style='text-align:right;'>$tongtien VND</td>
				<td>	
					<select name='edit_trangthai_ddh' id='edit_trangthai_ddh'>										
							$option
					</select>
				
				</td>
				<td align='center'>
					$ok_cancel_button
					<input name='hidMaDDH' id='hidMaDDH' type='hidden' value='$maDDH' />
				</td>
				<td align='center'>+</td>";
				echo $respone;
		}
		else
		{
			echo "Lỗi!!";
		}
	}
	
	
?>